package com.chunhe.sojourn.app.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.chunhe.sojourn.app.dao.ChannelDao;
import com.chunhe.sojourn.app.domain.Channel;
import com.chunhe.sojourn.app.service.ChannelService;
import com.chunhe.sojourn.common.domain.QueryRequest;
import com.chunhe.sojourn.common.utils.SortUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

@Service
public class ChannelServiceImpl extends ServiceImpl<ChannelDao, Channel> implements ChannelService {
    @Override
    public IPage<Channel> getPage(QueryRequest request) {
        Channel channel = new Channel();
        if(StringUtils.isNotBlank(request.getSearchParams())){
            channel = JSONObject.parseObject(request.getSearchParams(), Channel.class);
        }
        Page<Channel> page = new Page<>();
        SortUtil.handlePageSort(request, page, true);
        LambdaQueryWrapper<Channel> lambdaQueryWrapper = new LambdaQueryWrapper<Channel>()
                .like(StringUtils.isNotBlank(channel.getChannelName()),Channel::getChannelName, channel.getChannelName());
        return this.page(page, lambdaQueryWrapper);
    }
}
